<?php
namespace slinks\common\util;

/**
 * Description of ObjectUtil
 *
 * @author navid
 */
class ObjectUtil {
   
    /**
     * Initializes the given object with values from the options array. 
     * All keys found in the options array with a cooresponding setter will be passed the value for that key.
     * @param mixed $object the object to initialize
     * @param array $options the values to pass to the setters.
     */
    public static function initializeWithSetters($object,$options=array()){

        if($object === null || $options === null){
            throw new \InvalidArgumentException('$object an $options must not be null');
        }

        // Set each parameter on the object if possible
        // TODO: get object setters then look for parameters. More than likely all setters want values. Where there could be a lot of variables that do not need injecting.
        foreach ($options as $paramName => $paramValue) {
            $callable = array($object, 'set' . ucfirst($paramName));

            if (is_callable($callable)) {
                call_user_func($callable, $paramValue);
            }
        }
    }

}
